<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of hoadon
 *
 * @author sonUIT
 */
class Hoadon extends CI_Controller {
    public function __construct() {
        parent::__construct();
        $this->load->model("mhoadon");
    }
    public function index(){
         
        $hd=new Mhoadon(); 
         echo ($hd->Max("MAHD"));
    }
    public function insert()
    {
        
     $hd=new Mhoadon();     
    // $hd->set_mahd($hd->Max("MAHD")+1);
     $hd->set_matk($this->session->userdata('matk'));     
     $hd->set_diachi($this->input->post('diachi'));
     $hd->set_ngaydat(  date("Y-m-d H:i:s"));
     $hd->set_ngaygiao($this->input->post("ngaygiao"));
     $hd->set_sodt($this->input->post("sodt"));
     $hd->set_tennn($this->input->post("tennn"));
     
     if( $hd->Save())
     {
         $giohang = $this->cart->contents();
        foreach ($giohang as $hang) {
            $cthd = new Mcthd();
            $cthd->set_dongia($hang['price']);
            $cthd->set_masp($hang['id']);
            $cthd->set_soluong($hang['qty']);
            $cthd->set_so_hoadon($hoadon->get_so_hoadon());
            $cthd->Save();
        }
        // xoa gio hang khi da them vao chi tiet
        $this->cart->destroy();;
     }
    }
}

?>
